/*
 * 已售设备列表
 * @Author: LuoQianJun
 * @Date: 2018-03-31 17:53:05
 * @Last Modified by: ljb
 * @Last Modified time: 2018-09-26 18:06:53
 */
<template>
	<div class="v-admin-sell-equipment-index">

		<Table
			:columns="columns"
			:loading="loading"
			:data="sellDevices"
			:height="tableHeight(1)"
			border
			class="personal-scrollbar"
			@on-sort-change="sortable"/>

	</div>
</template>

<script>
import { Button } from 'iview';
import { computedTableHeight } from 'src/views/mixins/computedTableHeight'; // 引入mixins文件

export default {
	name: 'SellIndex',
	mixins: [computedTableHeight],
	props: {
		loading: {
			type: Boolean,
			default() {
				return false;
			},
		},
		sellDevices: {
			type: Array,
			default() {
				return [];
			},
		},
		customers: {
			type: Object,
			default() {
				return {};
			},
		},
	},
	data() {
		return {
			columns: [
				{
					title: this.$t('equipment.customer_id'),
					key: 'customer_id',
					align: 'center',
					render: (h, { row }) => <div> { this.customers[row.customer_id] || '-' } </div>,
				},
				{
					title: this.$t('equipment.code'),
					key: 'code',
					align: 'center',
					render: (h, { row }) => <div> { row.purchase_device.device.code || '-' } </div>,

				},
				{
					title: this.$t('equipment.device_name'),
					key: 'device_name',
					align: 'center',
					render: (h, { row }) => <div> { row.purchase_device.device.device_name || '-' } </div>,

				},
				{
					title: this.$t('equipment.specification'),
					key: 'specification',
					align: 'center',
					render: (h, { row }) => <div> { row.purchase_device.device.specification || '-' } </div>,

				},
				{
					title: this.$t('equipment.producer'),
					key: 'producer',
					align: 'center',
					render: (h, { row }) => <div> { row.purchase_device.device.producer || '-' } </div>,

				},
				{
					title: this.$t('equipment.operator'),
					key: 'operator',
					align: 'center',
					render: (h, { row }) => <div> { row.operator || '-' } </div>,

				},
				{
					title: this.$t('equipment.num'),
					key: 'num',
					width: 180,
					align: 'center',
					sortable: 'custom',
					render: (h, { row }) => <div> { row.num || '-' } </div>,
				},
				{
					title: this.$t('equipment.sold_at'),
					key: 'sold_at',
					width: 180,
					align: 'center',
					sortable: 'custom',
					render: (h, { row }) => <div>{ row.sold_at ? row.sold_at : '' }</div>,
				},
				{
					title: this.$t('common.operation'),
					align: 'center',
					width: 180,
					render: (h, { row }) => (
						<div>
							<Button size="small" style={{ marginRight: '5px' }} on-click={() => { this.$emit('show', row.device_accounts, row.id); }} type="primary">
								{ this.$t('equipment.account_information') }
							</Button>
						</div>
					),
				},

			],
		};
	},

	methods: {
		/**
         * 排序的回调
         * @param  {Object} param {对应列的属性对象,里面包含了column列属性，key值，order排序字段}
         * @return {undefined}
         */
		sortable(param) {
			const search_param = {
				order_by: param.order === 'normal' ? '' : param.key,

				sort: param.order === 'normal' ? '' : param.order.toLocaleUpperCase(),
			};

			this.$emit('sort', search_param);
		},


	},
};
</script>
